home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / HideMenubarEtc / ShowHideCorners.c < prev    next >
Encoding:
Text File  |  1995-06-16  |  4.6 KB  |  154 lines  |  [TEXT/MMCC]

  1. // ShowHideCorners.c
  2. //
  3. // David Hayward 
  4. // Developer Technical Support
  5. // AppleLink: DEVSUPPORT
  6. //
  7. // Copyrite 1993, Apple Computer,Inc
  8. //
  9. // This file contains routines to sho/hide the
  10. // rounded corners in each monitor.
  11. // 
  12. // 12/10/93    david    first cut
  13.  
  14.  
  15. #include <Windows.h>
  16. #include <QuickDraw.h>
  17. #include <LowMem.h>
  18.  
  19. #include "ShowHideUtils.h"
  20. #include "ShowHideCorners.h"
  21.  
  22.  
  23. /**\
  24. |**| ==============================================================================
  25. |**| GLOBALS
  26. |**| ==============================================================================
  27. \**/
  28. short        gCornersState = SHOW;
  29. RgnHandle    crnrRgn;
  30.  
  31.  
  32. /**\
  33. |**| ==============================================================================
  34. |**| PRIVATE FUNCTION PROTOTYPES
  35. |**| ==============================================================================
  36. \**/
  37. void GetCornerRgn (RgnHandle crnrRgn);
  38.  
  39.  
  40. /**\
  41. |**| ==============================================================================
  42. |**| PUBLIC FUNCTIONS
  43. |**| ==============================================================================
  44. \**/
  45.  
  46.  
  47. /*------------------------------------------------------------------------------*\
  48.     SetCornersState
  49.  *------------------------------------------------------------------------------*
  50.         changes the corners state to either SHOW or HIDE
  51. \*------------------------------------------------------------------------------*/
  52. void SetCornersState (char vis)
  53. {
  54.     static short    first = true;
  55.     RgnHandle        GrayRgn = LMGetGrayRgn();
  56.     
  57.     if (first)                                /* if its the 1st time called */
  58.     {                                            /* this oviously doen't do much but */
  59.         first = false;                        /* I include it to emphasize the */
  60.     }                                            /* parallel with SetCornersState() */
  61.     
  62.     if (vis == gCornersState)            /* return if nothing would change */
  63.         return;
  64.         
  65.     if (!vis)                                /* if HIDE */
  66.     {
  67.         crnrRgn = NewRgn();
  68.         GetCornerRgn(crnrRgn);                    /* make a region for the corners */
  69.         UnionRgn(GrayRgn,crnrRgn,GrayRgn);    /* tell the desktop it covers the corners */
  70.  
  71.         SH_ForceUpdate(crnrRgn);
  72.     }
  73.     
  74.     else                                        /* if SHOW */
  75.     {
  76.         GrafPtr savePort;
  77.         
  78.         GetPort(&savePort);
  79.         
  80.         SetPort(LMGetWMgrPort());
  81.         SetClip(crnrRgn);
  82.         FillRgn(crnrRgn,&(qd.black));            /* redraw the corners */
  83.         
  84.         SetPort(savePort);
  85.         
  86.         DiffRgn(GrayRgn, crnrRgn, GrayRgn);    /* remove the corners from the desktop rgn */
  87.         DisposeRgn(crnrRgn);                        /* dispose to the corners region */
  88.     }
  89.     gCornersState = !gCornersState;            /* toggle the state */
  90. }
  91.  
  92.  
  93. /*------------------------------------------------------------------------------*\
  94.     GetCornersState
  95.  *------------------------------------------------------------------------------*
  96.         an accessor to allow others to read private gCornersState global
  97. \*------------------------------------------------------------------------------*/
  98. char GetCornersState (void)
  99. {
  100.     return gCornersState;
  101. }
  102.  
  103.  
  104. /**\
  105. |**| ==============================================================================
  106. |**| PRIVATE FUNCTIONS
  107. |**| ==============================================================================
  108. \**/
  109.  
  110.  
  111. /*------------------------------------------------------------------------------*\
  112.     GetCornerRgn
  113.  *------------------------------------------------------------------------------*
  114.         uses globals to calculate the region for the rounred corners
  115.         the RgnHandle crnrRgn must be allocated with NewRgn() before calling
  116. \*------------------------------------------------------------------------------*/
  117. void GetCornerRgn (RgnHandle crnrRgn)
  118. {
  119.     Rect            mBarRect;
  120.     RgnHandle        tmpRgn;
  121.     Rect            gDeviceRect;
  122.     GDHandle        gDevice;
  123.     RgnHandle        GrayRgn = LMGetGrayRgn();
  124.  
  125.     tmpRgn = NewRgn();                            
  126.     
  127.     /* Get the handle to the first device in the list. */
  128.     gDevice = GetDeviceList();
  129.     
  130.     /* Loop through all the devices in the list in order */
  131.     /* to create a region for all the screens' boundaries*/
  132.     while (gDevice != nil)
  133.     {
  134.         gDeviceRect = (**gDevice).gdRect;            /* the bounding rect of this device */
  135.         RectRgn(tmpRgn, &gDeviceRect);                /* convert rect to a region */
  136.         UnionRgn(crnrRgn,tmpRgn,crnrRgn);            /* add device's rect to region */
  137.         gDevice = GetNextDevice( gDevice );            /* get next device and repeat... */
  138.     }
  139.     
  140.     /* subtract the GrayRgn from the above. This leaves a region */
  141.     /* which contains the menuBar and any rounded corners. */
  142.     DiffRgn(crnrRgn,GrayRgn,crnrRgn);                /* remove GrayRgn from crnrRgn */
  143.  
  144.  
  145.     /* now subtract the MenuBar region (if any). */
  146.     /* This leaves just the rounded corners. */
  147.     mBarRect = qd.screenBits.bounds;                    /* create a rect for the mbar */
  148.     mBarRect.bottom = mBarRect.top + GetMBarHeight();
  149.     RectRgn(tmpRgn, &mBarRect);                        /* make a region for the mbar */
  150.     DiffRgn(crnrRgn,tmpRgn,crnrRgn);                    /* remove mbar from crnrRgn */
  151.  
  152.     DisposeRgn(tmpRgn);
  153. }
  154.